<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('阀门信息列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
    <div class="ui-layout-west">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa icon-grid"></i> 住户资料
                </div>
                <div class="box-tools pull-right">
                    <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i class="fa fa-refresh"></i></button>
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div>
    <div class="ui-layout-center">
         <div class="container-div">
            <div class="row">
                <div class="col-sm-12 search-collapse">
                    <form id="formId">
                        <input type="hidden" id="locationId" name="locationId">
                        <div class="select-list">
                            <ul>
                                <li>
                                    <label>阀门ID：</label>
                                    <input type="text" name="valveId"/>
                                </li>
                                <li>
                                    <label>阀门型号：</label>
                                    <select id="typeId" name="typeId">
                                        <option value="">所有</option>
                                        <option th:each="type:${types}" th:value="${type.typeId}" th:text="${type.typeName}" th:field="${typeId}"></option>
                                    </select>
                                </li>
                                <li>
                                    <label>采集器ID：</label>
                                    <input type="text" id="collectorId" name="collectorId" th:value="${collectorId}"/>
                                </li>

                                <li class="select-time">
                                    <label>安装时间：</label>
                                    <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
                                    <span>-</span>
                                    <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>

                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success" onclick="add()" shiro:hasPermission="base:unitValve:info:add">
                        <i class="fa fa-plus"></i> 添加
                    </a>
                    <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="base:unitValve:info:edit">
                        <i class="fa fa-edit"></i> 修改
                    </a>
                    <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="base:unitValve:info:remove">
                        <i class="fa fa-remove"></i> 删除
                    </a>
                    <a class="btn btn-warning" onclick="$.table.importExcel()" shiro:hasPermission="base:unitValve:info:import">
                        <i class="fa fa-upload"></i> 导入
                    </a>
                    <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="base:unitValve:info:export">
                        <i class="fa fa-download"></i> 导出
                    </a>
                  <!--  <a class="btn btn-success multiple disabled" onclick="register()" shiro:hasPermission="base:unitValve:info:register">
                        <i class="fa fa-plus"></i> 登记
                    </a>
                    <a class="btn btn-danger multiple disabled" onclick="cancel()" shiro:hasPermission="base:unitValve:info:cancel">
                        <i class="fa fa-remove"></i> 注销
                    </a>-->
                    <a class="btn btn-success multiple disabled" onclick="aperture()" shiro:hasPermission="base:unitValve:info:aperture">
                        <i class="fa fa-edit"></i> 阀门开度
                    </a>
                   <!-- <a class="btn btn-danger multiple disabled" onclick="limit()" shiro:hasPermission="base:unitValve:info:limit">
                        <i class="fa fa-download"></i> 限制开启
                    </a>-->
                    <a class="btn btn-success multiple disabled" onclick="check()" shiro:hasPermission="base:unitValve:info:check">
                        <i class="fa fa-plus"></i> 数据采集
                    </a>
                    <a class="btn btn-success multiple disabled" onclick="pids()" shiro:hasPermission="base:unitValve:info:pids">
                        <i class="fa fa-plus"></i> 打开PID参数远程修改
                    </a>
                    <a class="btn btn-success multiple disabled" onclick="pidsf()" shiro:hasPermission="base:unitValve:info:pidsf">
                        <i class="fa fa-plus"></i> 关闭PID参数远程修改
                    </a>
                    <a class="btn btn-success multiple disabled" onclick="pidw()" shiro:hasPermission="base:unitValve:info:pidw">
                        <i class="fa fa-plus"></i> 打开PID功能
                    </a>
                    <a class="btn btn-success multiple disabled" onclick="pidwf()" shiro:hasPermission="base:unitValve:info:pidwf">
                        <i class="fa fa-plus"></i> 关闭PID功能
                    </a>
                    <a class="btn btn-success multiple disabled" onclick="temp()" shiro:hasPermission="base:unitValve:info:temp">
                        <i class="fa fa-edit"></i> 阀门温度
                    </a>
                </div>
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('base:unitValve:info:edit')}]];
        var removeFlag = [[${@permission.hasPermi('base:unitValve:info:remove')}]];
        var prefix = ctx + "base/unitValve/info";

        var registers = [[${@dict.getType('register_s')}]];
        var registerw = [[${@dict.getType('register_w')}]];

        $(function() {
            var panehHidden = false;
            if ($(this).width() < 769) {
                panehHidden = true;
            }
            $('body').layout({ initClosed: panehHidden, west__size: 185 });
            queryInfoList();
            queryLocationTree();
        });

        function queryInfoList() {
            var options = {
                url: prefix + "/list",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importUrl: prefix + "/importData",
                importTemplateUrl: prefix + "/importTemplate",
                modalName: "阀门信息",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'valveId',
                    title: '阀门id',
                    formatter: function(value, row, index) {
                        return '<a href="javascript:void(0)" onclick="data(\'' + row.valveId + '\')">' + value + '</a>';
                    }
                },
                {
                    field: 'type.typeName',
                    title: '阀门型号'
                },
                {
                    field: 'location.locationName',
                    title: '安装地址'
                },
                {
                    field: 'collectorId',
                    title: '采集器id'
                },
                {
                    field: 'installTime',
                    title: '安装时间'
                },

                    {
                        field: 'registerS',
                        title: 'PID参数修改',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(registers, value);
                        }
                    },
                    {
                        field: 'registerW',
                        title: 'PID功能',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(registerw, value);
                        }
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.valveId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.valveId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        }

        function queryLocationTree()
        {
            var url = ctx + "base/location/treeData";
            var options = {
                url: url,
                expandLevel: 2,
                onClick : zOnClick
            };
            $.tree.init(options);

            function zOnClick(event, treeId, treeNode) {
                $("#locationId").val(treeNode.id);
                $.table.search();
            }
        }

        $('#btnExpand').click(function() {
            $._tree.expandAll(true);
            $(this).hide();
            $('#btnCollapse').show();
        });

        $('#btnCollapse').click(function() {
            $._tree.expandAll(false);
            $(this).hide();
            $('#btnExpand').show();
        });

        $('#btnRefresh').click(function() {
            queryLocationTree();
        });

        /* 采集器新增 */
        function add() {
            var locationId = $("#locationId").val();
            if(locationId==''){
                locationId = 1;
            }
            var typeId = $("#typeId").val();
            if(typeId == ''){
                typeId = 0;
            }
            var collectorId = $("#collectorId").val();
            if(collectorId == ''){
                collectorId = 0;
            }
            var url = prefix + '/add/'+locationId+'/'+typeId+'/'+collectorId;
            $.modal.open("阀门新增", url);
        }



        /* 设定阀门开度 */
        function aperture(){
            var rows = $("#bootstrap-table").bootstrapTable('getSelections');
            for(var i=0;i<rows.length;i++){
                var row = rows[i];
                var registerW = row["registerW"];
                if(registerW=="1"){
                    $.modal.alertWarning("此功能只有在PID功能关闭后才能使用");
                    return;

            }
            rows = $.table.selectFirstColumns();
            var url = prefix + '/aperture/' + rows.join();
            $.modal.open("设置阀门开度", url, '800', '300');
        }}

        /* 设定阀门温度 */
        function temp(){
            var rows = $("#bootstrap-table").bootstrapTable('getSelections');
            for(var i=0;i<rows.length;i++){
                var row = rows[i];
                var registerW = row["registerW"];
                if(registerW=="0"){
                    $.modal.alertWarning("PID功能未打开");
                    return;

            }
            rows = $.table.selectFirstColumns();
            var url = prefix + '/temp/' + rows.join();
            $.modal.open("设置阀门开度", url, '800', '300');
        }}



        /* 读取阀门数据 */
        function check(){
            var rows = $("#bootstrap-table").bootstrapTable('getSelections');
            for(var i=0;i<rows.length;i++){
                var row = rows[i];


            }
            rows = $.table.selectFirstColumns();
            $.ajax({
                url: prefix + "/check/" + rows.join(),
                cache: false,
                contentType: false,
                processData: false,
                type: 'POST',
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍后...");
                    $.modal.disable();
                },
                success: function (result) {
                    if (result.code == web_status.SUCCESS) {
                        $.modal.closeAll();
                        $.modal.alertSuccess(result.msg);
                        $.table.refresh();
                    } else if (result.code == web_status.WARNING) {
                        $.modal.enable();
                        $.modal.alertWarning(result.msg);
                    } else {
                        $.modal.enable();
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                }
            });
        }

        /* 打开pid参数修改 */
        function pids(){
            var rows = $("#bootstrap-table").bootstrapTable('getSelections');
            for(var i=0;i<rows.length;i++){
                var row = rows[i];


            }
            rows = $.table.selectFirstColumns();
            $.ajax({
                url: prefix + "/pids/" + rows.join(),
                cache: false,
                contentType: false,
                processData: false,
                type: 'POST',
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍后...");
                    $.modal.disable();
                },
                success: function (result) {
                    if (result.code == web_status.SUCCESS) {
                        $.modal.closeAll();
                        $.modal.alertSuccess(result.msg);
                        $.table.refresh();
                    } else if (result.code == web_status.WARNING) {
                        $.modal.enable();
                        $.modal.alertWarning(result.msg);
                    } else {
                        $.modal.enable();
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                }
            });
        }
        /* 关闭pid参数修改 */
        function pidsf(){
            var rows = $("#bootstrap-table").bootstrapTable('getSelections');
            for(var i=0;i<rows.length;i++){
                var row = rows[i];


            }
            rows = $.table.selectFirstColumns();
            $.ajax({
                url: prefix + "/pidsf/" + rows.join(),
                cache: false,
                contentType: false,
                processData: false,
                type: 'POST',
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍后...");
                    $.modal.disable();
                },
                success: function (result) {
                    if (result.code == web_status.SUCCESS) {
                        $.modal.closeAll();
                        $.modal.alertSuccess(result.msg);
                        $.table.refresh();
                    } else if (result.code == web_status.WARNING) {
                        $.modal.enable();
                        $.modal.alertWarning(result.msg);
                    } else {
                        $.modal.enable();
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                }
            });
        }

        /* 打开pid功能 */
        function pidw(){
            var rows = $("#bootstrap-table").bootstrapTable('getSelections');
            for(var i=0;i<rows.length;i++){
                var row = rows[i];
                var registerS = row["registerS"];
                if(registerS=="0"){
                    $.modal.alertWarning("此功能只有在PID参数修改打开后才能使用");
                    return;
                }
            }


            rows = $.table.selectFirstColumns();
            $.ajax({
                url: prefix + "/pidw/" + rows.join(),
                cache: false,
                contentType: false,
                processData: false,
                type: 'POST',
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍后...");
                    $.modal.disable();
                },
                success: function (result) {
                    if (result.code == web_status.SUCCESS) {
                        $.modal.closeAll();
                        $.modal.alertSuccess(result.msg);
                        $.table.refresh();
                    } else if (result.code == web_status.WARNING) {
                        $.modal.enable();
                        $.modal.alertWarning(result.msg);
                    } else {
                        $.modal.enable();
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                }
            });
        }
        /* 关闭pid功能 */
        function pidwf(){
            var rows = $("#bootstrap-table").bootstrapTable('getSelections');
            for(var i=0;i<rows.length;i++){
                var row = rows[i];
                var registerS = row["registerS"];
                if(registerS=="0"){
                    $.modal.alertWarning("此功能只有在PID参数修改打开后才能使用");
                    return;
                }

            }
            rows = $.table.selectFirstColumns();
            $.ajax({
                url: prefix + "/pidwf/" + rows.join(),
                cache: false,
                contentType: false,
                processData: false,
                type: 'POST',
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍后...");
                    $.modal.disable();
                },
                success: function (result) {
                    if (result.code == web_status.SUCCESS) {
                        $.modal.closeAll();
                        $.modal.alertSuccess(result.msg);
                        $.table.refresh();
                    } else if (result.code == web_status.WARNING) {
                        $.modal.enable();
                        $.modal.alertWarning(result.msg);
                    } else {
                        $.modal.enable();
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                }
            });
        }
        function data(valveId){
            var url = ctx + 'data/unitValve/' + valveId;
            $.modal.openTab("阀门采集数据", url);
        }
    </script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果厂商信息已经存在，更新这条数据。"> 是否更新已经存在的阀门信息
                &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>